home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
c
/
dice-3.16.lha
/
examples
/
TTXSame
/
DError.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-27
|
34KB
|
1,197 lines
//***********************************************************************
//* Copyright (c) 1993, 1994 Obvious Implementation Corp. *
//* All Rights Reserved. *
//* 207 Livingstone Drive, *
//* Cary N.C. 27513 - USA *
//***********************************************************************
#include <stdio.h>
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <string.h>
#include <stdlib.h>
#include <clib/exec_protos.h>
#include <lib/rexx.h>
#include <lib/misc.h>
#include "DError_rev.h"
#define PORTNAME "DICE_ERROR_PARSER" // This is what everyone else calls us by
extern __stkargs LONG SetRexxVar(struct RexxMsg *,char *,char *,ULONG);
struct ErrorInfo {
struct ErrorInfo *next; // Next error line in the list
struct ErrorInfo *prev; // Previous line in the list
char line[1]; // Text of the line. Note the [1] for the NULL
};
struct FileInfo {
struct FileInfo *next; // Next file entry in the list
struct FileInfo *prev; // Previous file entry in the list
char *source; // Source file that was compiled
char *dir; // Directory the file was compiled in
char *args; // Rexx arguments used for the compile
struct ErrorInfo base; // Root node for all lines
struct ErrorInfo *cur; // Current active error line
};
struct FileInfo files; // Root node for all files
struct FileInfo *curfile; // Current active error file
char *RexxHostName = NULL; // We will create the host ourseleves
#define MAX_FILENAME 1024
char buf[MAX_FILENAME+1];
char ebuf[512]; // AREXX return string holding buffer
short run_arexx_server;
//***************************************************************************
//* Procedure: AddLine *
//* Synopsis: AddLine(FileInfo *, char *) *
//* Purpose: Adds the line to the current file information. If there is *
//* not enough memory, it will simply ignore the line silently. *
//***************************************************************************
void AddLine(struct FileInfo *fi, char *line)
{
struct ErrorInfo *ei;
ei = malloc(sizeof(struct ErrorInfo) + strlen(line));
if (ei)
{
ei->prev = fi->base.prev;
ei->next = fi->base.prev->next;
strcpy(ei->line, line);
fi->base.prev->next = ei;
fi->base.prev = ei;
}
}
//******************************************************************************
//* Procedure: NewFile
//* Synopsis: FileInfo = NewFile(char *source, char *dir, char *args)
//* Purpose: Creates a new file info. If it is unable to, it returns NULL
//******************************************************************************
struct FileInfo *NewFile(char *source, char *dir, char *args)
{
struct FileInfo *fi;
fi = malloc(sizeof(struct FileInfo));
if (fi)
{
fi->source = strdup(source);
fi->dir = strdup(dir);
fi->args = strdup(args);
fi->cur = NULL;
if (fi->source != NULL &&
fi->dir != NULL &&
fi->args != NULL)
{
fi->prev = files.prev;
fi->next = files.prev->next;
files.prev->next = fi;
files.prev = fi;
fi->base.prev = fi->base.next = &fi->base;
}
else
{
if (fi->source) free(fi->source);
if (fi->dir) free(fi->dir);
if (fi->args) free(fi->args);
free(fi);
fi = NULL;
}
}
return(fi);
}
//************************************************************************
//* Procedure: FreeFile
//* Synopsis: FreeFile(struct FileInfo *)
//* Purpose: Removes a FileInfo structure from the list
//************************************************************************
void FreeFile(struct FileInfo *fi)
{
struct ErrorInfo *ei;
//
// Handle any attempts to free the base FI
//
if (fi == &files) return;
// Unlink us from the chain of file handles
fi->prev->next = fi->next;
fi->next->prev = fi->prev;
//
// Update any system pointers which might look at what we are going to free
//
if (curfile == fi)
{
curfile = NULL; // no more anyway
}
//
// Free all the lines
//
fi->base.prev->next = NULL; // mark our stopping point
for(ei = fi->base.next; ei != NULL;)
{
struct ErrorInfo *sei;
sei = ei;
ei = ei->next;
free(sei);
}
//
// Finally, get rid of the file information
//
free(fi->source);
free(fi->dir);
free(fi->args);
free(fi);
}
//***********************************************************************
//* Procedure: say
//* Synopsis: (void)say(msg);
//* Purpose: Displays the given message on the console
//***********************************************************************
void say(char *msg)
{
BPTR out;
out = Output();
if (out)
{
Write(out, msg, strlen(msg));
Write(out, "\n", 1);
}
}
//***********************************************************************
//* Procedure: usage
//* Synopsis: (void)usage();
//* Purpose: Displays the command line usage message - does not return
//***********************************************************************
void usage(void)
{
say("FILE/M,MACRO/K,PROJECT/K,REXXSTARTUP/S" VERSTAG);
exit(20);
}
//***********************************************************************
//* Procedure: dottx
//* Synopsis: result = dottx(port, cmd);
//* Purpose: Sends a command to TurboText
//***********************************************************************
char *dottx(char *port, char *cmd)
{
char *res;
long ec;
if (port == NULL) port = "TURBOTEXT";
PlaceRexxCommandDirect(NULL, port, cmd, &res, &ec);
return(res);
}
//***********************************************************************
//* Procedure: full_path
//* Synopsis: path = full_path(name)
//* Purpose: Constructs a fully expanded filename
//* Note, we can not assume that the file exists, so it will
//* not be possible to actually lock it. We can assume that
//* the directory it is part of does exist. Note that it can
//* return NULL if there is no memory available.
//***********************************************************************
char *full_path(char *name)
{
BPTR lock;
__aligned struct FileInfoBlock fib;
char *tail, *p;
int pos;
//
// Step 1 - split out any directory information from the actual name
//
p = strrchr(name, '/');
if (p == NULL) p = strrchr(name, ':');
if (p != NULL)
{
//
// There was some directory information involved
//
char c;
tail = strdup(p+1);
c = p[1];
p[1] = 0;
lock = Lock(name, SHARED_LOCK);
p[1] = c;
}
else
{
//
// No directory information involved, just the name relative to the
// current directory
//
lock = Lock("", SHARED_LOCK);
tail = strdup(name);
}
//
// Step 2 - we have the lock on the directory and the tail part of the name
// We want to construct a fully qualified path for the directory.
// If for some reason the lock on the directory returned 0, we want to just
// return the name they gave us to begin with.
//
if (lock == 0)
{
free(tail);
return(strdup(name));
}
//
// Step 3 - Fully qualify the directory portion into the buffer
//
if (DOSBase->dl_lib.lib_Version >= 36)
{
if (!NameFromLock(lock, buf, MAX_FILENAME))
{
//
// Either the name is too long or there was something else wrong with
// the file name, just return what they gave us as a start
//
UnLock(lock);
free(tail);
return(strdup(name));
}
UnLock(lock);
pos = 0;
}
else
{
// Running under